/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.faare.struts.service.beans;

import java.util.HashMap;
import java.util.Map;


/**
 * This is the top level element of the requests_conf.xml file.
 * It allows to define mappings between search form fields and searches business objects fields.
 */
public class JBRequests implements java.io.Serializable
{
    /** List of JBRequest. */
    private Map requestsMap = new HashMap();

    /** Creates new JBRequests. */
    public JBRequests()
    {
    }

    /** Gets list of search requests.
     * @return List of JBRequest
     */
    public Map getRequestsMap()
    {
        return requestsMap;
    }

    /**
     * Adds a request.
     *
     * @param req request
     */
    public void addRequest(JBRequest req)
    {
        requestsMap.put(req.getName().trim().toLowerCase(), req);
    }

    /**
     * Gets a request from its name.
     *
     * @param name request name
     *
     * @return request
     */
    public JBRequest findRequestByName(String name)
    {
        // rendre case insensitive en mettant le param en lowercase
        String key = name.trim().toLowerCase();

        return (JBRequest) requestsMap.get(key);
    }

    /**
     * Displays requests definition.
     *
     * @return String formatted requests definition
     */
    @Override
	public String toString()
    {
        StringBuffer buf = new StringBuffer();
        java.util.Iterator it = null;

        if (requestsMap != null)
        {
            buf.append("Map components of requestsMap = ");
            buf.append(System.getProperty("line.separator"));
            it = requestsMap.values().iterator();

            while (it.hasNext())
            {
                buf.append(".");
                buf.append(it.next());
                buf.append(System.getProperty("line.separator"));
            }
        }

        return buf.toString();
    }

    // end of toString method
}
